using System.Collections.Generic;
using UnityEngine;

public class SortShopGrid : MonoBehaviour
{
	public UIGrid grid;

	public void OnEnable()
	{
		SortGrid();
	}

	public void SortGrid()
	{
		if (grid == null)
		{
			grid = GetComponent<UIGrid>();
		}
		grid.sorting = UIGrid.Sorting.Alphabetic;
		List<Transform> childList = grid.GetChildList();
		childList.Sort((Transform a, Transform b) => InAppProduct.Comparator(a.GetComponent<InAppProduct>(), b.GetComponent<InAppProduct>()));
		Transform transform = null;
		for (int i = 0; i < childList.Count; i++)
		{
			for (int j = 0; j < childList.Count - 1; j++)
			{
				if (InAppProduct.Comparator(childList[j].GetComponent<InAppProduct>(), childList[j + 1].GetComponent<InAppProduct>()) == 1)
				{
					transform = childList[j + 1];
					childList[j + 1] = childList[j];
					childList[j] = transform;
				}
			}
		}
		for (int k = 0; k < childList.Count; k++)
		{
			childList[k].gameObject.name = (k + 100).ToString();
		}
		grid.repositionNow = true;
	}
}
